//
//  UINavigationBar+ZCLNavigationBar.m
//  RiceBasket
//
//  Created by DwZeng on 2021/1/15.
//

#import "UINavigationBar+ZCLNavigationBar.h"
#import <objc/runtime.h>

@implementation UINavigationBar (ZCLNavigationBar)

static char *AlphaV;
//#pragma - mark - 这个方法只会设置一次
//+ (void)initialize{
//    UINavigationBar *navigationBar = [UINavigationBar appearance];
//    [navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
//    [navigationBar NavAlphaWithColor:[PIC_SYS_COLOR_A colorWithAlphaComponent:1]];
//    
//    [navigationBar setTintColor:[UIColor whiteColor]];
//}

-(void)setAlphaView:(UIView *)AlphaView
{
    objc_setAssociatedObject(self, &AlphaV, AlphaView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(UIView *)AlphaView
{
    return objc_getAssociatedObject(self, &AlphaV);
}

-(void)NavAlphaWithColor:(UIColor *)color
{
    if (!self.AlphaView) {
        //设置图片
        [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
        
        //创建AlphaView
        self.AlphaView = [[UIView alloc]initWithFrame:CGRectMake(0, -statusHeight, [UIScreen mainScreen].bounds.size.width, navigationHeight)];
        
        //插入到nav...barshangqu
        [self insertSubview:self.AlphaView atIndex:0];
    }
    
    [self.AlphaView setBackgroundColor:color];
    
}

- (void)test
{
    unsigned int count;
    /**
     1.获取属性列表
     参数1:获取哪个类的
     参数2:count表示你该类里面有多少个属性
     
     propertyList 它就相当于一个数组
     
     数组里面就装着@property (nonatomic, copy) NSString *title;,@property (nonatomic, copy) NSString *digest;...
     */
    /**
     class_copyPropertyList 这个方法只能获取类的公有属性
     
     class_copyIvarList 能获取类的所有属性,包括私有属性
     */
    
    Ivar *propertyList = class_copyIvarList([UINavigationBar class], &count);
    
    for (int i=0; i<count; i++) {
        //2.取出objc_property_t数组中的property
        Ivar property = propertyList[i];
        
        //3.获取的是C语言的名称
        const char *cPropertyName = ivar_getName(property);
        
        //4.将C语言的字符串转成OC的
        NSString *ocPropertyName = [[NSString alloc] initWithCString:cPropertyName encoding:NSUTF8StringEncoding];
        
        //5.打印
        if ([ocPropertyName isEqualToString:@"_backgroundView"]) {
            
        }
    }
    
    //5.C语言中,用完copy,create的东西之后,最好释放
    free(propertyList);

}
@end
